package com.hhs.storage.controller;


import com.hhs.storage.bean.BusinessDocument;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.ResponseInfo;
import com.hhs.storage.service.BusinessDocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hhs
 * @since 2023-01-04
 */
@RestController
@RequestMapping("/businessDocument")
public class BusinessDocumentController {
    @Autowired
    private BusinessDocumentService businessDocumentService;

    @RequestMapping(value = "table")
    public Map<String, Object> getAll(BusinessDocument businessDocument, InputParam inputParam) {
        return businessDocumentService.getAll(businessDocument,inputParam,true);
    }

    //已下单列表
    @RequestMapping(value = "table/his")
    public Map<String, Object> getAllHis(BusinessDocument businessDocument, InputParam inputParam) {

        return businessDocumentService.getAllHis(businessDocument,inputParam);
    }
    @RequestMapping(value = "pendingOrderQuery")
    public Map<String, Object> pendingOrderQuery(BusinessDocument businessDocument, InputParam inputParam) {
        businessDocument.setState(BusinessDocument.STATUS_CREATE);//查询未完成订单
        return businessDocumentService.getAll(businessDocument,inputParam,false);
    }
    @PostMapping(value = "edit")
    public Map<String, Object> addOrUpdate(BusinessDocument businessDocument){
        return businessDocumentService.addOrUpdate(businessDocument);
    }
    @PostMapping(value = "dele")
    public Map dele(String id) {
        try{
            return businessDocumentService.dele(id);
        }catch (Exception e){
            return ResponseInfo.error("存在关联业务，无法删除");
        }
    }

}

